package com.example.grpc.client.helloworldStream;

import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.StatusRuntimeException;
import io.grpc.examples.hellostreaming.HelloReply;
import io.grpc.examples.hellostreaming.HelloRequest;
import io.grpc.examples.hellostreaming.StreamingGreeterGrpc;

import java.util.Iterator;

public class StreamSayHelloTenClient {
    public static void main(String[] args) {
        ManagedChannel channel = ManagedChannelBuilder.forAddress("172.16.36.76", 29080)
                .usePlaintext()
                .build();
        HelloRequest request = HelloRequest.newBuilder().setName("weiwei").build();
        StreamingGreeterGrpc.StreamingGreeterBlockingStub blockingStub = StreamingGreeterGrpc.newBlockingStub(channel);
       /* GreeterGrpc.GreeterBlockingStub blockingStub = GreeterGrpc.newBlockingStub(channel);

        HelloRequest request = HelloRequest.newBuilder().setName("weiwei").build();
        HelloReply response;*/
        Iterator<HelloReply> helloReplyIterator = null;
        try {
            helloReplyIterator = blockingStub.sayHelloTen(request);
            while (helloReplyIterator.hasNext()) {
                HelloReply response = helloReplyIterator.next();
                System.out.println("Message from gRPC-Server: " + response.getMessage());
            }
        } catch (StatusRuntimeException e) {
            System.out.println("RPC failed: {}" + e.getStatus());
            return;
        }

    }

}
